package com.qianfeng.biz.impl;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import com.qianfeng.biz.IUserBiz;
import com.qianfeng.dao.IUserDao;
import com.qianfeng.dao.impl.UserDaoImpl;
import com.qianfeng.dto.PageBean;
import com.qianfeng.entity.User;

public class UserBizImpl implements IUserBiz {
	
	private IUserDao userDao = new UserDaoImpl();

	@Override
	public int checkNameExits(String username) {
		return userDao.checkNameExits(username);
	}

	@Override
	public int addUser(User user) {
		return userDao.addUser(user);
	}

	@Override
	public User modifyInfo(User user, String nick_name, String sex, String birthday, String phone, String email,
			String address, String code) {
		Date shengri = null;
		try {
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
			shengri = sdf.parse(birthday);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		user.setNick_name(nick_name);
		user.setSex(sex);
		user.setBirthday(shengri);
		user.setPhone(phone);
		user.setEmail(email);
		user.setAddress(address);
		user.setCodes(code);
		return user;
	}

	@Override
	public int update(User user) {

			return userDao.update(user);
	}

	@Override
	public User checkLogin(User user) {
		return userDao.checkLogin(user);

	}

	@Override
	public User checkBackLogin(String username, int password) {
		return userDao.checkBackLogin(username,password);

	}

	@Override
	public PageBean queryall(int currPage) {
		PageBean pb=new PageBean();
		int count=userDao.querycount();
		int pageSize=4;
		int rowIndex=(currPage-1)*pageSize;
		double ct=count;
		Double tp=Math.ceil(ct/pageSize);
		int totalPage=tp.intValue();
		List<User> list=userDao.queryfenye(rowIndex,pageSize);
		pb.setTotalPage(totalPage);
		pb.setTotalCount(count);
		pb.setCurrPage(currPage);
		pb.setPageSize(pageSize);
		pb.setList(list);
		return pb;
	}

	@Override
	public User getUserById(int userid) {
		return userDao.getUserById(userid);
	}

	@Override
	public int updateUserInfo(User user) {
		return userDao.updateUserInfo(user);
	}

	@Override
	public int updateUserLockState(int userid, int lockstate) {
		return userDao.updateUserLockState(userid,lockstate);

	}

	@Override
	public int deleteById(int tid) {
		
		return userDao.deleteByid(tid);
	}

	@Override
	public int addUserInfo(User user) {
		return userDao.addUserInfo(user);

	}

}
